$(document).ready(function() {






	//物件類型
	$( "#object_styles" )
	  .bind( 'focus', function(){ 

	  	$(this).autocomplete("search"); 

	  }).bind( 'click', function(){ 

	  	$(this).autocomplete("search"); 
	  	
	  } )
	  .autocomplete({
		minLength: 0,
		source: function(request, response ) {
			//alert(request.term);
	                $.ajax({
	                    url: "/object_styles/object_style_josn",
	                    dataType: "json",
	                    data:{
						query: request.term
	                    },
	                    success: function( data ) {

	                        response( $.map( data, function( item ) {
	                        return {
								label: item.value,
								value: item.value
	                        }
	                        }));
	                    }
	                });
	    },
		focus: function() {
		  return false;
		},
		select: function( event, ui ) {
			 var terms=new Array();
			 if(this.value!="")
			   terms = this.value.split("/ ");
			 terms.pop();
			 terms.push( ui.item.value );
			 terms.push( "" );
			 this.value = terms.join( "/ " );
			 return false;
		}
	  });	
	  
	  	
	
	
	
	//市調狀態
	$( "#object_usage" )
	  .bind( 'focus', function(){ 
		
	  	$(this).autocomplete("search"); 

	  }).bind( 'click', function(){ 

	  	$(this).autocomplete("search"); 
	  	
	  } )
	  .autocomplete({
		minLength: 0,
		source: function(request, response ) {
			//alert(request.term);
	                $.ajax({
	                    url: "/object_usage/object_usage_josn",
	                    dataType: "json",
	                    data:{
						query: request.term
	                    },
	                    success: function( data ) {

	                        response( $.map( data, function( item ) {
	                        return {
								label: item.value,
								value: item.value
	                        }
	                        }));
	                    }
	                });
	    },
		focus: function() {
		  return false;
		},
		select: function( event, ui ) {
			 var terms=new Array();
			 if(this.value!="")
			   terms = this.value.split("/ ");
			 terms.pop();
			 terms.push( ui.item.value );
			 terms.push( "" );
			 this.value = terms.join( "/ " );
			 return false;
		}
	  });	
	  
	  
	  
	  
	  
	  
	  
	  

    
    $("#type_rent").click(function(){  
    	//alert('qq');  	    		
    		if( $("#type_rent").prop("checked") ){
	    		market_serial();
	    }	    
    });
	
	$("#type_sale").click(function(){    	    		
    		if( $("#type_sale").prop("checked") ){
	    		market_serial();
	    }	    
    });
    
    $("#object_usage").change(function(){    	    		
    		//if( $("#type_sale").prop("checked") ){
	    		market_serial();
	    //}	    
    });
    
});





function market_serial(){
	
		$.post("/object/market_serial", {
		       type_rent: $("#type_rent").prop("checked") , 
		       type_sale:$("#type_sale").prop('checked'), 
		       object_usage:$("#object_usage").val(),
		        
		    }, function(result) {
		        //$("#object_no").val(result);
		        $("#market_survey_no").val(result);
		        //market_survey_no
		    });
}


